package cn.kgc.bookservice.controller;

import cn.kgc.bookservice.service.BookService;
import cn.kgc.librarycommon.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/books")
    public PageResult<BookInfo> getAllBooks(Integer pageNo, String bookName, String authorName, Integer cid, Integer pageSize){
        pageNo = pageNo == null?1:pageNo;
        bookName = bookName == null?"":bookName;
        authorName = authorName == null?"":authorName;
        cid = cid == null?1:cid;
        return bookService.getAllBooks(pageNo, pageSize, bookName, authorName, cid);
    }

    @GetMapping("/categories")
    public List<Category> getAllCategory(){
        return bookService.getAllCategory();
    }

    @GetMapping("/borrow")
    public Integer borrow(Integer uid, Integer fid){
        return bookService.borrow(uid, fid);
    }

    @GetMapping("/goto_borrow")
    public List<BorrowVO> getBorrowById(Integer uid){
        return bookService.getBorrowById(uid);
    }
}